var salt = sessionStorage.getItem('usersalt');
var idrisk = getQueryVariable('id');
layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function() {
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : top.layer,
		$ = layui.jquery,
		laydate = layui.laydate,
		laytpl = layui.laytpl,
		table = layui.table;

	if(!sessionStorage.getItem('username')) {
		layer.msg('请先登录');
		setTimeout("top.location.href='../../../index.html'", 1000);

	}
	/*获取以销项的信息*/
	getriskclear();

	function getriskclear() {

		$.ajax({
			url: url + 'perilInfo/getInfo',
			dataType: 'json',
			async: false,
			type: "POST",
			data: {
				Token: salt,
				id: idrisk

			},
			success: function(data) {
				console.log(data);
				if(data.code == 0) {
					var list = data.data.perilInfo;

					$('#findUser').text(list.findUser); //发现人
					$('#findTime').text(list.findTime); //发现时间
					$('#typeId').text(list.typeName); //隐患类型
					$('#describe').text(list.describe); //隐患描述
					for(var i = 0; i < list.attachments.length; i++) {
						//    					$('#despic').append('<img src="'+url+"attachment/seekFile/"+list.attachments[i].id+'" width="100px" style="margin-right:20px;" />');
						$('#despic').append('<div style="display:inline-block;position:relative;margin:10px;" ><img id="pic' + list.attachments[i].id + '" onclick="lookbigpic(\'' + list.attachments[i].id + '\')" src="' + url + 'attachment/seekFile/' + list.attachments[i].id + '" width="100px" height="100px" class="picsty"/></div>')
					}

					$('#auditUser').text(list.auditUser); //核查人
					$('#auditTime').text(list.auditTime); //核查时间
					$('#finishTime').text(list.finishTime); //防控措施完成时间
					$('#auditFruit').text(list.auditFruit); //核查结论
					$('#auditStep').text(list.auditStep); //防控措施
					$('#leaderUser').text(list.leaderUser); //责任人
					$('#leaderUnits').text(list.leaderUnits); //责任单位

					$('#program').text(list.program); //治理方案

					var list1 = data.data.perilBills;
					var list1 = data.data.perilBills;

					for(var i = 0; i < list1.length; i++) {
						var flg = '';
						var goverfile = '';
						var schemepic = '';
						var result = '';
						/*获取文件*/
						if(list1[i].result == 0) {
							result = '<a style="color:#1c85d4">已销项</a>';
						} else if(list1[i].result == 1) {
							result = '未销项';
						} else {
							result = '';
						}

						//		      					$('#dutycompay').text(list1[i].leaderUnitsName);//责任单位
						//		      					$('#lushitime').text(list1[i].entTime)
						for(var l = 0; l < list1[i].attachmentsFile.length; l++) {

							goverfile += '<a style="color:#1c85d4; text-decoration:underline;" href="' + url + 'attachment/seekFile/' + list1[i].attachmentsFile[l].id + '">' + list1[i].attachmentsFile[l].originaName + '</a>&nbsp;&nbsp;';
						}
						for(var h = 0; h < list1[i].attachmentsImg.length; h++) {
							//		      						schemepic+='<img style="margin-right:20px;" width="100px" src="'+url+'attachment/seekFile/'+list1[i].attachmentsImg[h].id+'" />';
							schemepic += '<div style="display:inline-block;position:relative;margin:10px;" ><img id="pic' + list1[i].attachmentsImg[h].id + '" onclick="lookbigpic(\'' + list1[i].attachmentsImg[h].id + '\')" src="' + url + 'attachment/seekFile/' + list1[i].attachmentsImg[h].id + '" width="100px" height="100px" class="picsty"/></div>';
						}
						flg = '<tr><tr><td style="padding:0px;" colspan="6"><hr class="layui-bg-black"></td></tr>' +
							'<tr><td><label  style="font-weight:bold;color:black;">责任人</label></td><td><span  id="leaderUser" >' + list1[i].leaderUser + '</span></td>' +
							'<td><label  style="font-weight:bold;color:black;">责任单位</label></td><td><span id="dutycompay">' + list1[i].leaderUnitsName + '</span></td>' +
							'<td><label  style="font-weight:bold;color:black;">治理措施<br />落实时间</label></td><td><span id="lushitime" class="line-H40">' + list1[i].entTime + '</span></td></tr>' +
							'<tr><td><label  style="font-weight:bold;color:black;">治理方案</label></td><td colspan="5">' +
							'<span style="display: -webkit-box;word-break: break-all;-webkit-box-orient: vertical;overflow: hidden;text-overflow:ellipsis;">' + list1[i].program + '</span></td></tr>' +
							'<tr><td></td><td colspan="5"><div id="goverfile">' + goverfile + '</div></td></tr>' +
							'<tr><td><label style="font-weight:bold;color:black;">治理后照片</label></td><td colspan="5"><div  id="schemepic">' + schemepic + '</div></td></tr>'
						if(list1[i].type == 1) {
							flg = '<tr><tr><td style="padding:0px;" colspan="6"><hr class="layui-bg-black"></td></tr>' +
								'<tr><td><div class="layui-inline"><label class="fowei"><label class="fowei">销项核查人</label> </label></td><td>' +
								'<span >' + list1[i].leaderUser + '</span>' +
								'</div></td><td><div class="layui-inline"><label class="fowei">核查人单位</label></td><td>' +
								'<span >' + list1[i].leaderUnitsName + '</span>' +
								'</div></td><td><div class="layui-inline"><label class="fowei">治理措施<br />落实时间 </label></td><td>' +
								'<span >' + list1[i].entTime + '</span></div></td></tr><tr><td><label class="fowei">销项结论</label></td><td colspan="5"><span>' + result + '</span><td></tr>';
						}

						$('#newsdata').append(flg);
					}
					//    				for(var i=0;i<list1.length;i++){
					//    					if(list1[i].result==0){
					//    						
					//    						$('#leaderUser1').text(list1[i].leaderUser);//销项核查人
					//		      				$('#leaderUnits1').text(list1[i].leaderUnitsName);//核查人单位
					//		      				$('#entTime1').text(list1[i].entTime);//核查时间
					//		      				$('#entTime').text(list1[i].entTime);//治理措施落实时间
					//		      				$('#typetext').text('已销项');
					//    						/*取出文件 */
					//    						for(var k=0;k<list1[i].attachmentsFile.length;k++){
					//    							$('#riskfile').append('<a href="'+url+"attachment/seekFile/"+list1[i].attachmentsFile[k].id+'">'+list1[i].attachmentsFile[k].originaName+'</a>');
					//    						}
					//    						/*取出图片*/
					//    						for(var h=0;h<list1[i].attachmentsImg.length;h++){
					//    							$('#riskafterpic').append('<img src="'+url+"attachment/seekFile/"+list1[i].attachmentsImg[h].id+'" width="150px" height="150px" />');
					//    						}
					//    					}
					//    					
					//    					
					//    				}

				}

			},
			error: function(error) {
				console.log("获取失败");
			}
		});

	}

});

function lookbigpic(self) {

	var json = {
		"status": 1,
		"msg": "",
		"title": "",
		"id": 8,
		"start": 0,
		"data": [{
			"alt": "",
			"pid": 109,
			"src": url + "attachment/seekFile/" + self,
			"thumb": ""
		}]
	}
	layer.photos({
		photos: json,
		anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
	});

}